package etime

import "time"

const timeFormart = "2006-01-02 15:04:05"

//Time 转换输出格式
type Time time.Time

//UnmarshalJSON  json
func (t *Time) UnmarshalJSON(data []byte) (err error) {
	now, err := time.ParseInLocation(`"`+timeFormart+`"`, string(data), time.Local)
	*t = Time(now)
	return
}

//MarshalJSON  json
func (t Time) MarshalJSON() ([]byte, error) {
	b := make([]byte, 0, len(timeFormart)+2)
	b = append(b, '"')
	b = time.Time(t).AppendFormat(b, timeFormart)
	b = append(b, '"')
	return b, nil
}

//String 格式化
func (t Time) String() string {
	return time.Time(t).Format(timeFormart)
}
